#include <vector>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#define WIDTH 10
#define HEIGHT 5

namespace VFH{
typedef uint32_t MapContainer;
int index(int row, int col){
    return row * (WIDTH / sizeof(MapContainer)*8) + col;
}

void set_bit(MapContainer *map,int row,int col,int value){
    int idx = index(row, col);
    int offset = idx % (sizeof(MapContainer) * 8);
    int shift = sizeof(MapContainer) * 8 - offset - 1;
    if(value){
        map[idx/(sizeof(MapContainer) * 8)] |= (1 << shift);
    } else {
        map[idx/(sizeof(MapContainer) * 8)] &= ~(1 << shift);
    }
}

int get_bit(MapContainer *map, int row, int col){
    int idx = index(row, col);
    int offset = idx % (sizeof(MapContainer) * 8);
    int shift = sizeof(MapContainer) * 8 - offset - 1;
    return (map[idx/(sizeof(MapContainer) * 8)]>>shift) & 1;
}

class grid{
    private:
        int width;
        int height;
        std::vector<std::vector<int>> grid_data;
    public:
        grid(int _width,int _height,std::vector<std::vector<int>> _grid_data):\
        height(_height),width(_width),grid_data(_grid_data){}
        
        bool change_map(int x,int y, int label){
            if ((x<0 || x>width) || (y<0 || y>height)){
                return 1;
            } 
            
            grid_data[x][y] = label;
            return 0;
        }
};

class VFH{
    
};

};

int main(){
    VFH::MapContainer *map = (VFH::MapContainer*) \
        calloc(WIDTH * HEIGHT / (sizeof(VFH::MapContainer)*8)+1, sizeof(VFH::MapContainer));
    int i, j;

    // 初始化地图数据
    for(i = 0; j < HEIGHT;i++){
        for(j = 0; j < WIDTH; j++){
            VFH::set_bit(map,i,j,0);
        }
    }

    // 打印地图
    for(i = 0; j < HEIGHT;i++){
        for(j = 0; j < WIDTH; j++){
            printf("%d ",VFH::get_bit(map,i,j,0));
        }
        printf("\n");
    }

    free(map);
    return 0;
}